package com.ylxn;

import com.ylxn.mapper.IUserMapper;
import com.ylxn.mapper.OrderMapper;
import com.ylxn.pojo.Order;
import com.ylxn.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class test {
    @Test
    public void testOrder() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("sqlMapperConfig.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession openSession = sessionFactory.openSession();
        OrderMapper orderMapper = openSession.getMapper(OrderMapper.class);
        List<Order> list = orderMapper.findOrder();
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
    @Test
    public void testUser() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("sqlMapperConfig.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession openSession = sessionFactory.openSession();
        IUserMapper mapper = openSession.getMapper(IUserMapper.class);
        List<User> list = mapper.findUser();
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

    }
}
